//
//  takePhotoActionSheetV.m
//  carcareIOS
//
//  Created by 王然 on 16/7/27.
//  Copyright © 2016年 chezheng. All rights reserved.
//

#import "TakePhotoActionSheetV.h"
#define BTN_VIEW_HEIGHT (50)
#define SECTION_HEIGHT (5)


@implementation TakePhotoActionSheetV

-(void)dealloc{

}

- (instancetype)initWithFuncBtnArr:(NSArray *)funcBtn
{
    self = [super initWithFrame:[UIScreen mainScreen].bounds];
    if (self) {
        self.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.4];
        CGFloat firstBtnY =  __MAIN_HEIGHT - SECTION_HEIGHT - BTN_VIEW_HEIGHT * (funcBtn.count + 1);
        UIView * headBackV = [[UIView viewWithFrame:CGRectMake(0, 0, __MAIN_WIDTH, firstBtnY)] setupOnView:self];
        headBackV.backgroundColor = [UIColor clearColor];
        UITapGestureRecognizer * tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapGestute)];
        [headBackV addGestureRecognizer:tapGesture];
        
        CGFloat imageVY = 64 + 15 * __MAIN_RATIO_375;
        CGFloat imageVH = headBackV.height - imageVY - 40 * __MAIN_RATIO_375;
        UIImage * insuExampleImage = ImageNamed(@"insuExampleImage");
        CGFloat imageVW = imageVH / insuExampleImage.size.height * insuExampleImage.size.width;
        [[UIImageView imageViewWithFrame:CGRectMake((__MAIN_WIDTH - imageVW)  / 2, imageVY, imageVW, imageVH) image:insuExampleImage] setupOnView:headBackV];
        
        
        for (int index = 0; index < funcBtn.count + 1; index ++) {
            CGFloat btnY = firstBtnY + BTN_VIEW_HEIGHT * index + (index == funcBtn.count ? SECTION_HEIGHT : 0);
            
            if (index == funcBtn.count) {
                [[[UIView viewWithFrame:CGRectMake(0, btnY - SECTION_HEIGHT, __MAIN_WIDTH, SECTION_HEIGHT)] setupOnView:self] resetBackgroundColor:COLOR_HEXSTRING(@"#F2F2F2")];
            }
            
            UIButton * btn = [self createBtnViewWithFrame:CGRectMake(0, btnY, __MAIN_WIDTH, BTN_VIEW_HEIGHT) btnTitle:(index == funcBtn.count ? @"取消" : funcBtn[index])];
            btn.tag = index;
            [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
            
        }
    }
    return self;
}
- (void)tapGestute
{
    [self removeFromSuperview];
}
- (void)btnClick:(UIButton *)sender
{
    if([self.delegate respondsToSelector:@selector(actionSheetBtnClick:)])
    {
        [self.delegate actionSheetBtnClick:sender.tag];
    }
    [self removeFromSuperview];
}
- (UIButton *)createBtnViewWithFrame:(CGRect)frame btnTitle:(NSString *)btnTitle
{
    UIView * backV = [[[[UIView viewWithFrame:frame] setupOnView:self] resetBackgroundColor:[UIColor whiteColor]] resetBorderWidth:0.5 borderColor:COLOR_HEXSTRING(@"#D7D7D7")];
    [[[UILabel labelWithFrame:backV.bounds font:FONT_DEFAULT_Light(16) text:btnTitle textColor:[Theme wordColor]] setupOnView:backV]labelResetTextAlignment:NSTextAlignmentCenter];

    UIButton * btn = [[UIButton buttonEmptyWithFrame:backV.bounds click:nil] setupOnView:backV];
    return btn;
}

@end
